﻿using MDT.LifeSewagePlatform.Conmmon;
using MDT.LifeSewagePlatform.InterfaceService;
using MDT.LifeSewagePlatform.Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;

namespace MDT.LifeSewagePlatform.ServiceInstance.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    [Route("api/drugsta")]
    [Authorize]
    [ApiController]
    public class DrugStatisticsController : BaseController
    {
        #region ctor or prop
        [Autowired]
        private IDrugService drugService { get; set; }
        [Autowired]
        private IConfiguration configuration { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DrugStatisticsController()
        {
        }
        #endregion

        #region method service
        /// <summary>
        /// 饼状图
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("pie")]
        [CustomActionFilter(Role = RoleType.Child)]
        public async Task<BaseMessage> GetPie([FromQuery] PipeLineParameter query)
        {
            return await drugService.GetPie(query, CurrentUserInfo());
            
        }
        /// <summary>
        /// 右上方折线图数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("line")]
        [CustomActionFilter(Role = RoleType.Child)]
        public async Task<BaseMessage> GetLine([FromQuery] LineParameter query)
        {
            if (query.IsYear)
            {
                return await drugService.GetLineByYear(query, CurrentUserInfo());
            }
            else
            {
                return  await drugService.GetLineByMonth(query, CurrentUserInfo());
            }


        }
        /// <summary>
        /// 右上方折线图
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("line/drug")]
        [CustomActionFilter(Role = RoleType.Child)]
        public async Task<BaseMessage> GetLineDrug([FromQuery] LineParameter query)
        {
            if (query.IsYear)
            {
               
                return await drugService.GetLineByDrugYear(query, CurrentUserInfo());
            }
            else
            {
                return await drugService.GetLineByDrugMonth(query, CurrentUserInfo());
            }


        }
        /// <summary>
        /// 获取浓度
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet()]
        public async Task<BaseMessage> GetDrug([FromQuery] DrugParameter query)
        {

            return await drugService.GetDrugs(query, CurrentUserInfo());
            //foreach (var item in data)
            //{
            //    item.Morphine = Math.Round(item.Morphine, 2);
            //    item.Codeine = Math.Round(item.Codeine, 2);
            //    item.Methcathinone = Math.Round(item.Methcathinone, 2);
            //    item.Monoacetylmorphine_06 = Math.Round(item.Monoacetylmorphine_06, 2);
            //    item.Benzedrine = Math.Round(item.Benzedrine, 2);
            //    item.Methylamphetamine = Math.Round(item.Methylamphetamine, 2);
            //    item.PMMA = Math.Round(item.PMMA, 2);
            //    item.Ketamine = Math.Round(item.Ketamine, 2);
            //    item.NoKetamine = Math.Round(item.NoKetamine, 2);
            //    item.Cyclohexanone = Math.Round(item.Cyclohexanone, 2);
            //    item.MDA = Math.Round(item.MDA, 2);
            //    item.MDMA = Math.Round(item.MDMA, 2);
            //    item.Benzoylecgonine = Math.Round(item.Benzoylecgonine, 2);
            //    item.Cocaine = Math.Round(item.Cocaine, 2);
            //    item.Cotinine = Math.Round(item.Cotinine, 2);
            //}
        }

        /// <summary>
        /// 毫克/天/千人
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("details")]
        public async Task<BaseMessage> GetDrugDetail([FromQuery] DrugParameter query)
        {

            return await drugService.GetDrugDetals(query, CurrentUserInfo());
            //foreach (var item in data)
            //{
            //    item.Morphine = Math.Round(item.Morphine, 2);
            //    item.Codeine = Math.Round(item.Codeine, 2);
            //    item.Methcathinone = Math.Round(item.Methcathinone, 2);
            //    item.Monoacetylmorphine_06 = Math.Round(item.Monoacetylmorphine_06, 2);
            //    item.Benzedrine = Math.Round(item.Benzedrine, 2);
            //    item.Methylamphetamine = Math.Round(item.Methylamphetamine, 2);
            //    item.PMMA = Math.Round(item.PMMA, 2);
            //    item.Ketamine = Math.Round(item.Ketamine, 2);
            //    item.NoKetamine = Math.Round(item.NoKetamine, 2);
            //    item.Cyclohexanone = Math.Round(item.Cyclohexanone, 2);
            //    item.MDA = Math.Round(item.MDA, 2);
            //    item.MDMA = Math.Round(item.MDMA, 2);
            //    item.Benzoylecgonine = Math.Round(item.Benzoylecgonine, 2);
            //    item.Cocaine = Math.Round(item.Cocaine, 2);
            //    item.Cotinine = Math.Round(item.Cotinine, 2);
            //}
        }
        /// <summary>
        /// 历史极值
        /// </summary>
        /// <param name="Params"></param>
        /// <returns></returns>
        [HttpGet("history/top")]
        [CustomActionFilter(Role = RoleType.General)]
        public async Task<BaseMessage> GetHistoryTop([FromQuery] TopParameter Params)
        {
            return  await drugService.GetHistoryTop(Params, CurrentUserInfo());
        }
        /// <summary>
        /// 排行
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        [HttpGet("rank")]
        [CustomActionFilter(Role = RoleType.Child)]
        
        public async Task<BaseMessage> GetRank([FromQuery] PieParameter para)
        {
            return await drugService.GetRank(para, CurrentUserInfo());
        }
        /// <summary>
        /// 折算总量排行
        /// </summary>
        /// <param name="Params"></param>
        /// <returns></returns>
        [HttpGet("rank/total")]
        [CustomActionFilter(Role = RoleType.Child)]
        public async Task<BaseMessage> GetRankTotal([FromQuery] PieParameter Params)
        {
            return await drugService.GetRankTotal(Params, CurrentUserInfo());
        }
        /// <summary>
        /// 综合分析
        /// </summary>
        /// <param name="Params"></param>
        /// <returns></returns>
        [HttpGet("synthesize")]
        [CustomActionFilter(Role = RoleType.Child)]
        public async Task<BaseMessage> GetSynthesize([FromQuery] SynthesizeParameter Params)
        {
            return await drugService.GetSynthesize(Params, CurrentUserInfo());
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Params"></param>
        /// <returns></returns>
        [HttpGet("changescpe")]
        [CustomActionFilter(Role = RoleType.Child)]
        public async Task<BaseMessage> GetChangeScpe([FromQuery] PieParameter Params)
        {
            return await drugService.GetChangeScpe(Params, CurrentUserInfo());
        }

        /// <summary>
        /// 通过城市获取检测点
        /// </summary>
        /// <param name="companyid"></param>
        /// <param name="cityid"></param>
        /// <returns></returns>
        [HttpGet("monitoringsite/{companyid}/{cityid}")]
        public async Task<BaseMessage> ByCityGetMonitoringSite(int companyid, int cityid)
        {
            if (IsAdmin() == false)
            {
                companyid = GetCompanyID();
                GetCurrentAreaID();
                GetRoleID();
            }

            int currentArea=GetCurrentAreaID();
            int roleId=GetRoleID();
            return await drugService.GetAreas(cityid,companyid,currentArea,roleId);
        }
        /// <summary>
        /// 获取日销量
        /// </summary>
        /// <param name="Params"></param>
        /// <returns></returns>
        [HttpGet("drugday")]
        public async Task<BaseMessage> GetDrugDay([FromQuery] DrugDayParameter Params)
        {

            //var data = await drugService.GetDrugDays(Params, CurrentUserInfo());
            //foreach (var item in data)
            //{
            //    item.MDMA = Math.Round(item.MDMA, 2);
            //    item.Cocaine = Math.Round(item.Cocaine, 2);
            //    item.Morphine = Math.Round(item.Morphine, 2);
            //    item.Methylamphetamine = Math.Round(item.Methylamphetamine, 2);
            //    item.Cyclohexanone = Math.Round(item.Cyclohexanone, 2);
            //    item.Ketamine = Math.Round(item.Ketamine, 2);
            //}
            return await drugService.GetDrugDays(Params, CurrentUserInfo());
        }
        /// <summary>
        /// 获取日期
        /// </summary>
        /// <param name="Params"></param>
        /// <returns></returns>
        [HttpGet("date")]
        public async Task<BaseMessage> GetDate([FromQuery] DateParameter Params)
        {

            if (IsAdmin() == false)
            {
                Params.CompanyID = GetCompanyID();
            }

            //var data = await drugService.GetDate(Params);
            return await drugService.GetDate(Params);
        }
        #endregion
    }
}
